2.2 Precedence and Subexpressions

Figure 2.3 tells only part of the story. It shows that an expression is a list of operands alternating with binary operators. What is missing is the order in which operators are applied. While an expression like a+b*c conforms to the syntax rule given in 2.3, being a sequence of operands and binary operators, it is conventional to interpret such an expression as a+(b*c). This is true both in arithmetic and in computer languages. The interpretation in which one operation is performed before another is called “operator precedence”. We say that multiplication has a higher precedence than addition. Within the same precedence, operators are applied left to right (except for exponentiation).

The precedence of operators in Myron is given in Figure 2.4. The table also shows where primaries and unary operators fit into the precedence scheme.

CategoryOperators
Primary constructs §2.3, §2.10.1 variables, numbers,
bracketing operators, other primaries
Postfix unary operators §2.4.3 §2.10.2 !, °, ɓ, ℓ, ,
C, D, G, J, L, N, P, T, -1,
ⅈ, ɽ, ʋ, ƈ, ʈ, ʂ, ɱ, ɗ,
parameters, indexes
Prefix unary operators §2.4 -, +, ¬, ±, #, ∠, √, ∇, ↓, ↑
log, ln, root, trigonometrics
infix binary and n-ary operators ^, √, ∧, ↓, ↑
§2.4.1 §2.10.3 ·, ×, /, ÷, //, ¦, ⊕, ⋂, ∘
+, -, ±, ∓, ∨, ∪, ∖, △
∈, ∉, ⊆, ⊂, ⊈, ⊄, ‖, ‖‖
=, ≠, <, ≤, >;, ≥, ≈
≡, ⇒
ternary operator §2.8.2 ?:
definition §2.5
Figure 2.4 Operator Precedence